//
//  RootViewController.m
//  UI8_UITableView
//
//  Created by dllo on 15/11/18.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITableView *tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    
    tableV.delegate = self;
    tableV.dataSource = self;
    
    [self.view addSubview:tableV];
    [tableV release];
    
    
    UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 100)] autorelease];
    view.backgroundColor = [UIColor greenColor];
    tableV.tableHeaderView = view;
    
    
    
    
    
    
    
}

// 每个区的头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    // 头视图的大小坐标与view设置的frame无关,高度取决于heightForHeaderInSection协议方法
    UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
    view.backgroundColor = [UIColor redColor];
    return view;
}

// 每个区的头视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}

// 设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

// 选中行时触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"触发的行号%ld 触发的区号:%ld", indexPath.row, indexPath.section);
}

// 分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

// 分区头标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"区标题";
}

// 右侧竖排索引
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    NSArray *arr = [NSArray arrayWithObjects:@"A", @"B", @"C", nil];
    return arr;
}

// 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return 5;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *cellStr = @"cell";
    // 到重用池中取cell, 若有cell则直接使用,若无则创建新的cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    
    if (nil == cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellStr] autorelease];
//        NSLog(@"%d", __LINE__);
    }
   
    //    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    //
    //    NSLog(@"%d", __LINE__);
    
    cell.textLabel.text = @"王宁";
    cell.detailTextLabel.text = @"🐷";
    cell.imageView.image = [UIImage imageNamed:@"image.png"];
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    
    return cell;
    
}
// cell辅助button触发方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"触发的行号%ld 触发的区号:%ld", indexPath.row, indexPath.section);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
